package com.dengqi.mymodule.activity.guide;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.MainActivity;
import com.dengqi.mymodule.R;

import androidx.annotation.Nullable;

/**
 * setProgressType：正转/反转
 * setOutLineColor：外部轮廓颜色
 * setOutLineWidth：外部轮廓宽度
 * setInCircleColor：圆的背景色
 * setProgressColor：进度条颜色
 * setProgressLineWidth：进度条宽度
 * setProgress：进度条起始位置
 * setTimeMillis：等待时间
 *
 * reStart：重置并开始
 * setCountdownProgressListener：设置监听
 *
 * 没有坑
 *
 * Created by dell on 2018/6/19
 */

public class Splash2Activity extends BaseActivity {


    SkipTextView mSkipTextView;
    boolean isClick = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_splash2);

        /**
         * 隐藏状态栏
         */
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隐藏nav栏
                        | View.SYSTEM_UI_FLAG_FULLSCREEN//隐藏状态栏
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        );


        mSkipTextView = findViewById(R.id.tv_skip);
        //默认：SkipTextView.ProgressType.COUNT_BACK
        mSkipTextView.setProgressType(SkipTextView.ProgressType.COUNT);
        mSkipTextView.reStart();

        mSkipTextView.setCountdownProgressListener(1, new SkipTextView.OnCountdownProgressListener() {
            @Override
            public void onProgress(int what, int progress) {
                if (what == 1 && (progress == 100 || progress == 0) && !isClick) {
                    toMainActivity();
                }

            }
        });

        mSkipTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isClick = true;
                toMainActivity();
            }
        });

    }

    public void toMainActivity() {
        startActivity(new Intent(Splash2Activity.this, MainActivity.class));
        overridePendingTransition(0, 0);
    }

    /**
     * 重写onDestroy
     * 不让AppManager.finishCurrentActivity();
     * 否则跳转会异常
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) { //拦截/屏蔽返回键
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
